package com.leyou.common.advice;

import com.leyou.common.exception.LyException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 定义异常处理
 */
@ControllerAdvice
public class ControllerExceptionAdvice {

    @ExceptionHandler(RuntimeException.class) //声明此方法可以处理RuntimeException的异常
    public ResponseEntity<String> handleException(LyException e){
        return ResponseEntity.status(e.getStatus()).body(e.getMessage());
    }
}
